n = int(input())
if 1000 <= n <= 9999:
    d = 0
    m = 0
    for i in range(2, n):
        if n % i == 0:
            d += 1
    if d == 0:
        m = n

    w = n % 1000
    d = 0
    
    for i in range(2, w):
        if w % i == 0:
            d += 1
    if d == 0 and w > m:
        m = w


    r = n // 10
    d = 0
    for i in range(2, r):
        if r % i == 0:
            d += 1
    if d == 0 and r > m:
        m = r
    print (m)

else:
    print(0)
